package com
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	import com.UI.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.filters.BlurFilter;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.plaf.*;
	import org.aswing.skinbuilder.SkinProgressBarBackground;
	import org.aswing.skinbuilder.SkinProgressBarForeground;
	
	import spark.primitives.*;
	
	public class SceneBattle extends SceneBase
	{
		public static const 	BATTLE_TYPE_PVE:uint = 1;
		public static const 	BATTLE_TYPE_PVP_COMPARE:uint = 2;
		public static const 	BATTLE_TYPE_PVP_PK:uint = 3;
		public static const 	BATTLE_TYPE_PVP_ENSLAVE:uint = 4;
		public static const 	BATTLE_TYPE_PVP_CATCH_LOVER:uint = 5;
		
		
		public static const 	BATTLER_TYPE_NULL:uint = 0;
		public static const 	BATTLER_TYPE_PLAYER:uint = 1;
		public static const 	BATTLER_TYPE_PET:uint = 2;
		public static const 	BATTLER_TYPE_SLAVE:uint = 3;	
		public static const 	BATTLER_TYPE_LOVER:uint = 4;	
		public static const 	BATTLER_TYPE_MONSTER:uint = 5;
		
		public static const 	BATTLER_STATE_NORMAL:uint = 0;
		public static const 	BATTLER_STATE_DEAD:uint = 1;
		public static const 	BATTLER_STATE_TP:uint = 2;
		public static const 	BATTLER_STATE_HL:uint = 3;	
		public static const 	BATTLER_STATE_BD:uint = 4;	
		public static const 	BATTLER_STATE_CM:uint = 5;
		public static const 	BATTLER_STATE_SL:uint = 6;
		public static const 	BATTLER_STATE_QS:uint = 7;
		public static const 	BATTLER_STATE_RM:uint = 8;
		public static const 	BATTLER_STATE_SIZE:uint = 9;

		public static const 	EFFECT_ID_BJ:uint = 1000001;
		public static const 	EFFECT_ID_SB:uint = 1000002;
		public static const 	EFFECT_ID_FJ:uint = 1000003;
		public static const 	EFFECT_ID_LJ:uint = 1000004;
		public static var m_arBattlers:Array = new Array();
		m_arBattlers[0] = new Array();
		m_arBattlers[1] = new Array();
		
		public static var teamSelf:uint;
		public static var indexSelf:uint;
		public static var teamSelfPartner:uint;
		public static var indexSelfPartner:uint;
		public static var nRowCount:Array = new Array();
		
		public static var roundPlayBattler:Array = new Array();
		public static var roundPlayStep:uint = 0;
		public static var nBattleType:int = 0;
		public static var nLearning:int = 0;
		public static var tweenArray:Array = new Array();
		public var _battleBackground:BitmapData;
		public static var objSelf:Object = null;
		public static var bgBattle:DisplayObject = null;
		public function SceneBattle()
		{
			super();
			
			Engine.W = 1200;
			Engine.H = 600;
			
			if(_battleBackground != null)
			{
				_battleBackground.dispose();
				_battleBackground = null;
			}
			_battleBackground = new BitmapData(Engine.W,Engine.H,true,0x00000000);
			
			if(_mainBitmap != null)
			{
				removeChild(_mainBitmap);
				_mainBitmap = null;
			}
			_mainBitmap = new Bitmap(_mainBitmapData);
			_mainBitmap.alpha = 1.0;
			addChildAt(_mainBitmap,0);
			
			bgBattle = Client.getUIElement("img_battle_bg") as DisplayObject;
			addChildAt(bgBattle,1);
			
			Client.getInstance().addEventListener("302", phRoundBegin_302);
			Client.getInstance().addEventListener("303", phRoundEnd_303);
			Client.getInstance().addEventListener("305", phRoundPlay_305);
			Client.getInstance().addEventListener("306", phBattleEnd_306);
			
			var objSkillCSV:Object = Client.getInstance().GetSkillCSV(9);
			_effect_target_hit[BATTLER_STATE_HL] = objSkillCSV.effect_target_hit;
			trace("_effect_target_hit[BATTLER_STATE_HL]:"+_effect_target_hit[BATTLER_STATE_HL]);
			objSkillCSV = Client.getInstance().GetSkillCSV(14);
			_effect_target_hit[BATTLER_STATE_BD] = objSkillCSV.effect_target_hit;
			objSkillCSV = Client.getInstance().GetSkillCSV(19);
			_effect_target_hit[BATTLER_STATE_CM] = objSkillCSV.effect_target_hit;
			objSkillCSV = Client.getInstance().GetSkillCSV(24);
			_effect_target_hit[BATTLER_STATE_SL] = objSkillCSV.effect_target_hit;
			objSkillCSV = Client.getInstance().GetSkillCSV(45);
			_effect_target_hit[BATTLER_STATE_QS] = objSkillCSV.effect_target_hit;
			objSkillCSV = Client.getInstance().GetSkillCSV(44);
			_effect_target_hit[BATTLER_STATE_RM] = objSkillCSV.effect_target_hit;


		}
		private static var _effect_target_hit:Array = new Array;
		//private static var _effect_target_hit:int = 0;
		private static var _instance:* = null;
		public static function getInstance():SceneBattle
		{
			if(_instance == null)
				_instance = new SceneBattle();
			return _instance;
		}
		static public function phEnterBattle_300(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phEnterBattle_300", msg);
			var nIndex:uint = 0;
			SceneBattle.nBattleType = msg[nIndex++];
			SceneBattle.nLearning = msg[nIndex++];
			SceneBattle.nRowCount[0] = msg[nIndex++];
			SceneBattle.nRowCount[1] = msg[nIndex++];
			var nCount:uint = msg[nIndex++];
			if(nCount <= 0) return;
			if(PanelMain.getInstance().isInBattle && waitingLeaveBattle)
			{
				FrameBattleEndWin.hide();
				FrameBattleEndLose.hide();
				PanelMain.getInstance().leaveBattle();
			}
			PanelMain.getInstance().enterBattle();
			//SceneBattle.getInstance().enterBattleEffect();
			if(SceneBattle.m_arBattlers[0].length > 0)
				SceneBattle.m_arBattlers[0].splice(0,SceneBattle.m_arBattlers[0].length);
			if(SceneBattle.m_arBattlers[1].length > 0)
				SceneBattle.m_arBattlers[1].splice(0,SceneBattle.m_arBattlers[1].length);
			var array:Array = new Array();
			for(var i:uint = 0; i < nCount; i++)
			{
				var team:uint = msg[nIndex++];
				var index:uint = msg[nIndex++];
				
				var obj:Object = new Object();
				SceneBattle.m_arBattlers[team][index] = obj;
				obj.team = team;
				obj.index = index;
				
				obj.type = msg[nIndex++];
				if(obj.type == 0)
					continue;
				obj.m_nBattlerId = msg[nIndex++];
				obj.bSoul = msg[nIndex++];
				obj.m_nCharId = msg[nIndex++];
				obj.m_nPetId = msg[nIndex++];
				obj.m_nLoverId = msg[nIndex++];
				obj.m_nSlaveId = msg[nIndex++];
				obj.m_nMonsterId = msg[nIndex++];
				
				obj.name = msg[nIndex++];
				obj.m_nRace = msg[nIndex++];
				obj.m_nGender = msg[nIndex++];
				obj.m_nLevel = msg[nIndex++];

				obj.equip_count = msg[nIndex++];
				obj.equip_image0 = msg[nIndex++];
				obj.equip_image1 = msg[nIndex++];
				obj.equip_image2 = msg[nIndex++];
				obj.equip_image3 = msg[nIndex++];
				obj.equip_image4 = msg[nIndex++];
				obj.equip_image5 = msg[nIndex++];
				obj.m_nImageId = msg[nIndex++];

				array.splice(0,array.length);
				if(obj.m_nImageId != 0)
				{
					array.push(Engine.assetMapMonsterPath + "npc_"+ obj.m_nImageId + '.swf');
				}
				else
				{
					array.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image0 + '.swf');
					array.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image1 + '.swf');
					array.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image2 + '.swf');
					array.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image3 + '.swf');
					array.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image4 + '.swf');
					array.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image5 + '.swf');
				}
				obj.image_id = msg[nIndex++];

				obj.state = new Array;
				for(var j:int = 0; j < BATTLER_STATE_SIZE; j++)
				{
					obj.state[j] = msg[nIndex++];
				}
				obj.hp_change = msg[nIndex++];
				
				obj.hp = msg[nIndex++];
				obj.hp_max = msg[nIndex++];
				
				obj.m_nHP = obj.hp;
				obj.m_nHPMax = obj.hp_max;
				obj.m_nAP = msg[nIndex++];
				obj.m_nDP = msg[nIndex++];
				obj.m_nSP = msg[nIndex++];
				
				obj.m_nResistHL = msg[nIndex++];
				obj.m_nResistBD = msg[nIndex++];
				obj.m_nResistHS = msg[nIndex++];
				
				var objChar:ObjectChar = null;
				var needSetUI:Boolean = false;
				
				if(obj.bSoul == 1)
				{
					objChar = SceneBattle.getInstance().getObjectByBattlerId(obj.m_nBattlerId);
					if(objChar == null)
					{
						if(obj.type == BATTLER_TYPE_PLAYER || obj.type == BATTLER_TYPE_LOVER || obj.type == BATTLER_TYPE_SLAVE)
						{
							objChar = SceneBattle.getInstance().createCharSoul(array
								,"char_"+ obj.image_id + '.swf',obj.name,SceneBattle.getInstance().getPosition(team,SceneBattle.nRowCount[team], index),obj.m_nGender,true);
							(objChar as ObjectCharSoul).soulId = obj.m_nBattlerId;
						}
						
						if(obj.type == BATTLER_TYPE_PET)
						{
							objChar = SceneBattle.getInstance().createCharSoul([Engine.assetMapMonsterPath + "npc_"+ obj.image_id + '.swf']
								,"npc_"+ obj.image_id + '.swf',obj.name,SceneBattle.getInstance().getPosition(team,SceneBattle.nRowCount[team],index),obj.m_nGender,true);
							(objChar as ObjectCharSoul).soulId = obj.m_nBattlerId;
						}
						needSetUI = true;
					}
					else
					{
						if(obj.type == BATTLER_TYPE_PLAYER || obj.type == BATTLER_TYPE_LOVER || obj.type == BATTLER_TYPE_SLAVE)
						{
							(objChar as ObjectCharSoul).load(array,"char_"+ obj.image_id + '.swf');
							(objChar as ObjectCharSoul).soulId = obj.m_nBattlerId;
						}
						
						if(obj.type == BATTLER_TYPE_PET)
						{
							objChar.load([Engine.assetMapMonsterPath + "npc_"+ obj.image_id + '.swf'],"npc_"+ obj.image_id + '.swf');
							(objChar as ObjectCharSoul).soulId = obj.m_nBattlerId;
						}
						
					}
				}
				else
				{
					objChar = SceneBattle.getInstance().getObjectByBattlerId(obj.m_nBattlerId);
					if(objChar == null)
					{
						if(obj.type == BATTLER_TYPE_PLAYER || obj.type == BATTLER_TYPE_LOVER || obj.type == BATTLER_TYPE_SLAVE)
						{
							objChar = SceneBattle.getInstance().createCharPlayer(array
								,"char_"+ obj.image_id + '.swf',obj.name,SceneBattle.getInstance().getPosition(team,SceneBattle.nRowCount[team], index),obj.m_nGender,true);
							(objChar as ObjectCharPlayer).charId = obj.m_nBattlerId;
						}
						
						if(obj.type == BATTLER_TYPE_PET)
						{
							objChar = SceneBattle.getInstance().createCharPet(Engine.assetMapMonsterPath + "npc_"+ obj.image_id + '.swf'
								,"npc_"+ obj.image_id + '.swf',obj.name,SceneBattle.getInstance().getPosition(team,SceneBattle.nRowCount[team],index),true);
							(objChar as ObjectCharPet).petId = obj.m_nBattlerId;
						}
						needSetUI = true;
					}
					else
					{
						if(obj.type == BATTLER_TYPE_PLAYER || obj.type == BATTLER_TYPE_LOVER || obj.type == BATTLER_TYPE_SLAVE)
						{
							(objChar as ObjectCharPlayer).load(array,"char_"+ obj.image_id + '.swf');
							(objChar as ObjectCharPlayer).charId = obj.m_nBattlerId;
						}
						
						if(obj.type == BATTLER_TYPE_PET)
						{
							(objChar as ObjectCharPet).load([Engine.assetMapMonsterPath + "npc_"+ obj.image_id + '.swf'],"npc_"+ obj.image_id + '.swf');
							(objChar as ObjectCharPet).petId = obj.m_nBattlerId;
						}
						
					}
					
					if(obj.m_nCharId == CharInfo.charId)
					{
						SceneBattle.teamSelf = team;
						SceneBattle.indexSelf = index;
						SceneBattle.objSelf = obj;
					}
					
					if(CharInfo.m_nBattlePartnerType == PanelMain.PARTNER_TYPE_LOVER && obj.m_nLoverId == CharInfo.objLover.loverId)
					{
						SceneBattle.teamSelfPartner = team;
						SceneBattle.indexSelfPartner = index;
					}
						
					if(CharInfo.m_nBattlePartnerType == PanelMain.PARTNER_TYPE_SLAVE && CharInfo.m_nSlaveJoinBattleIndex >=0 && obj.m_nSlaveId == CharInfo.m_arSlaves[CharInfo.m_nSlaveJoinBattleIndex].id)
					{
						SceneBattle.teamSelfPartner = team;
						SceneBattle.indexSelfPartner = index;
					}
					
					if(CharInfo.m_nBattlePartnerType == PanelMain.PARTNER_TYPE_PET && CharInfo.m_nPetJoinBattleIndex >=0 && obj.m_nPetId == CharInfo.m_arPets[CharInfo.m_nPetJoinBattleIndex].id)
					{
						SceneBattle.teamSelfPartner = team;
						SceneBattle.indexSelfPartner = index;
					}
				}
				
				if(obj.type == BATTLER_TYPE_MONSTER)
				{
					objChar = SceneBattle.getInstance().getObjectByBattlerId(obj.m_nBattlerId);
					if(objChar == null)
					{
						objChar = SceneBattle.getInstance().createCharMonster(Engine.assetMapMonsterPath + "npc_"+ obj.image_id + '.swf'
							,"npc_"+ obj.image_id + '.swf',obj.name,SceneBattle.getInstance().getPosition(team,SceneBattle.nRowCount[team],index),true);
						(objChar as ObjectCharMonster).monsterId = obj.m_nBattlerId;
						needSetUI = true;
					}
					else
					{
						(objChar as ObjectCharMonster).load([Engine.assetMapMonsterPath + "npc_"+ obj.image_id + '.swf'],"npc_"+ obj.image_id + '.swf');
						(objChar as ObjectCharMonster).monsterId = obj.m_nBattlerId;
					}
				}
				if(objChar._tooltip == null)
				{
					objChar._tooltip = new ToolTipBattler;
					objChar._tooltip.setTargetComponent(objChar);
					objChar._tooltip.setWaitThenPopupEnabled(false);
				}
				(objChar._tooltip as ToolTipBattler).setItem(obj);
				objChar._tooltip.disposeToolTip();
				
				objChar.setName(obj.name);
				objChar.setLevel(obj.m_nLevel);
				obj.objChar = objChar;
				if(obj.hp_max == 0)
				{
					obj.hp_max = obj.hp_max + 1;
				}
				objChar.setHP(obj.hp,obj.hp_max);
				objChar.direction = (team == 0 ? Directions.Right : Directions.Left);
				//objChar.setAction(Actions.Prepare);
				objChar.userObject = obj;
				
				//objChar.setAction(Actions.Prepare);
				var pt:Point = SceneBattle.getInstance().getPosition(team,SceneBattle.nRowCount[team],index)
				objChar.setPos(pt.x,pt.y);
				if(needSetUI)
				{
					objChar.setAction(Actions.Prepare);
					objChar.alpha = 1.0;
					objChar.stop = false;
				}
				
				if(obj.hp_change != 0)
					//objChar.addEffectHPChange(obj.hp_change,1.5);
					addHPChange(objChar,obj.hp_change);
				
				if(needSetUI)
				{
					var ui:ComponentUI = objChar.barHP.getUI();
					ui.putDefault("ProgressBar.border", null);
					ui.putDefault("ProgressBar.bg", SkinProgressBarBackground);
					ui.putDefault("ProgressBar.fg", SkinProgressBarForeground);
					ui.putDefault("ProgressBar.horizotalBGImage", Client.getUIElement("img_p_bg") as DisplayObject);
					ui.putDefault("ProgressBar.horizotalFGImage", Client.getUIElement("img_hp") as DisplayObject);
					objChar.barHP.setUI(ui);
				}
				
				updateEffect(objChar,obj.state);
				if((obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0) && objChar.action != Actions.Die)
				{
					objChar.setAction(Actions.Die,
						function(objCharTarget:ObjectChar):void
						{
							objCharTarget.alpha = 0.5;
							//RoundPlayNext();
						},[objChar],true);
				}
				
				if(obj.state[BATTLER_STATE_DEAD] != 1 && obj.hp > 0)
				{
					objChar.setAction(Actions.Prepare);
					objChar.stop = false;
					objChar.alpha = 1;
				}

			}
			if(SceneBattle.teamSelf == 1)
			{
				var _point:Point;
				var _obj:Object = null;
				for each ( _obj in SceneBattle.m_arBattlers[0])
				{
					if(_obj.objChar is ObjectChar)
					{
						_obj.objChar.isBattler = false;
						_point = SceneBattle.getInstance().getPosition(1,SceneBattle.nRowCount[0],_obj.index);
						(_obj.objChar as ObjectChar).setPos(_point.x,_point.y);
						_obj.objChar.direction =  Directions.Left;
						_obj.objChar.isBattler = true;
					}
				}
				for each ( _obj in SceneBattle.m_arBattlers[1])
				{
					if(_obj.objChar is ObjectChar)
					{
						_obj.objChar.isBattler = false;
						_point = SceneBattle.getInstance().getPosition(0,SceneBattle.nRowCount[1],_obj.index);
						(_obj.objChar as ObjectChar).setPos(_point.x,_point.y);
						_obj.objChar.direction =  Directions.Right;
						_obj.objChar.isBattler = true;
					}
				}
			}
			
		}
		static public function phLeaveBattle_301(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phLeaveBattle_301", msg);
			var nIndex:uint = 0;
			var m_nCharId:uint = msg[nIndex++];
			trace("phLeaveBattle_301,m_nCharId:",m_nCharId);
			if(m_nCharId == CharInfo.charId)
			{
				PanelMain.getInstance().leaveBattle();
			}
			else
			{
				var obj:ObjectBase = SceneBattle.getInstance().getObjectByCharId(m_nCharId);
				SceneBattle.getInstance().removeObject(obj);
				trace("phLeaveBattle_301,obj:"+obj+"m_nCharId:",m_nCharId);
			}
		}
		
		public static var isWaitUseSkill:Boolean = false;
		public function phRoundBegin_302(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phRoundBegin_302", msg);
			var nIndex:uint = 0;
			var nRound:uint = msg[nIndex++];

			if(CharInfo.m_nBattleMode == 1)
			{
				FrameBattle.show();
				FrameBattle.hidePartner();
			}
			if(CharInfo.m_nBattleMode == 0)
			{
				FrameBattle.hide();
				FrameBattle.hidePartner();
			}
			isWaitUseSkill = true;
			if(SceneBattle.nLearning == 1)
			{
				FrameBattle.hide();
				FrameBattle.hidePartner();
				isWaitUseSkill = false;
			}
			//isWaitUseSkill = true;
		}
		
		public function phRoundEnd_303(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phRoundEnd_303", msg);
			var nIndex:uint = 0;
			var nRound:uint = msg[nIndex++];
		}
		
		public function phRoundPlay_305(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phRoundPlay_305", msg);
			var nIndex:uint = 0;
			var nRound:uint = msg[nIndex++];
			var nCount:uint = msg[nIndex++];
			roundPlayBattler.splice(0,roundPlayBattler.length);
			for(var i:int = 0; i < nCount; i++)
			{
				var obj:Object = new Object;
				roundPlayBattler[i] = obj;
				obj.team = msg[nIndex++];
				obj.index = msg[nIndex++];
				obj.skillid = msg[nIndex++];
				obj.hp_change = msg[nIndex++];
				obj.hp = msg[nIndex++];
				obj.hp_max = msg[nIndex++];
				if(obj.state == null)
					obj.state = new Array;
				for(var j:int = 0; j < BATTLER_STATE_SIZE; j++)
				{
					obj.state[j] = msg[nIndex++];
				}
				obj.skillTarget = null;
				obj.skillTarget = new Array();
				var nSkillTargetCount:uint = msg[nIndex++];
				for(j = 0; j < nSkillTargetCount; j++)
				{
					var objTarget:Object = new Object;
					obj.skillTarget[j] = objTarget;
					objTarget.team = msg[nIndex++];
					objTarget.index = msg[nIndex++];
					objTarget.hp_change = msg[nIndex++];
					objTarget.hp = msg[nIndex++];
					objTarget.hp_max = msg[nIndex++];
					if(objTarget.state == null)
						objTarget.state = new Array;
					for(var k:int = 0; k < BATTLER_STATE_SIZE; k++)
					{
						objTarget.state[k] = msg[nIndex++];
					}
					objTarget.m_bBJ = msg[nIndex++];
					objTarget.m_bSB = msg[nIndex++];
					objTarget.m_bFJ = msg[nIndex++];
					objTarget.m_nFJHPChange = msg[nIndex++];
					objTarget.m_bLJ = msg[nIndex++];
					objTarget.m_nLJHPChange1 = msg[nIndex++];
					objTarget.m_nLJHPChange2 = msg[nIndex++];
				}
			}
			roundPlayStep = 0;
			isWaitUseSkill = false;
			FrameBattle.hide();
			FrameBattle.hidePartner();
			RoundPlay();
		}

		static public var waitingLeaveBattle:Boolean = false;
		static public var objLastBattleEndAdd:Object = [];
		
		public function phBattleEnd_306(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phBattleEnd_306", msg);
			var nIndex:uint = 0;
			var m_nCharId:uint = msg[nIndex++];
			var nResult:uint = msg[nIndex++];
			var nBattleType:uint = msg[nIndex++];
			FrameBattle.hide();
			FrameBattle.hidePartner();
			
			waitingLeaveBattle = true;
			if(nBattleType == BATTLE_TYPE_PVE)
			{
				
				objLastBattleEndAdd.m_nLastBattleEndAddEXP = msg[nIndex++];
				objLastBattleEndAdd.m_nLastBattleEndAddEXPP = msg[nIndex++];
				objLastBattleEndAdd.m_nLastBattleEndAddMoney = msg[nIndex++];
				objLastBattleEndAdd.m_nLastBattleEndAddWood = msg[nIndex++];
				objLastBattleEndAdd.m_nLastBattleEndAddFood = msg[nIndex++];
				objLastBattleEndAdd.m_listLastBattleEndAddItems = [];
				var array:Array = objLastBattleEndAdd.m_listLastBattleEndAddItems;
				array.splice(0,array.length);
				var nCount:uint = msg[nIndex++];
				for(var i:int = 0; i < nCount; i++)
				{
					var obj:Object = new Object();
					array[i] = obj;
					obj.csv_id = msg[nIndex++];
					if(obj.csv_id == 0)
					{
						continue;
					}
					obj.count = msg[nIndex++];
					obj.equip_level = msg[nIndex++];
					obj.equip_hp = msg[nIndex++];
					obj.equip_ap = msg[nIndex++];
					obj.equip_dp = msg[nIndex++];
					obj.equip_sp = msg[nIndex++];
					
					obj.equip_enhanceHL = msg[nIndex++];
					obj.equip_enhanceBD = msg[nIndex++];
					obj.equip_enhanceHS = msg[nIndex++];
					
					obj.equip_resistHL = msg[nIndex++];
					obj.equip_resistBD = msg[nIndex++];
					obj.equip_resistHS = msg[nIndex++];
					
					obj.equip_prop_BJ = msg[nIndex++];
					obj.equip_prop_SB = msg[nIndex++];
					obj.equip_prop_FJ = msg[nIndex++];
					obj.equip_prop_LJ = msg[nIndex++];
					
					obj.creator_char_gender = msg[nIndex++];
					obj.creator_char_name = msg[nIndex++];
					obj.creator_lover_gender = msg[nIndex++];
					obj.creator_lover_name = msg[nIndex++];
					
				}
				

				if(nResult == 1)
					FrameBattleEndWin.show();
				else
					FrameBattleEndLose.show();
				return;

			}
			var nCharIdOther:uint  = 0;
			var strCharNameOther:String  = '';
			if(nResult == 1 && nBattleType == BATTLE_TYPE_PVP_CATCH_LOVER)
			{
				nCharIdOther  = msg[nIndex++];
				strCharNameOther  = msg[nIndex++];
				if(strCharNameOther != null && strCharNameOther.length > 0)
				{
					FrameInfo.showMessageDialog("","你战胜了 "+strCharNameOther+",是否抓作情人?",function handleOptionAddLover(button:uint):void
					{
						if(button == JOptionPane.YES)
						{
							Client.getInstance().sendPacketLogic(1200,[_nTmpCharIdOther]);
						}
					},null,true,null,JOptionPane.YES|JOptionPane.NO);
					_nTmpCharIdOther = nCharIdOther;
				}
				//PanelMain.getInstance().leaveBattle();
			}
			
			if(nResult == 1 && nBattleType == BATTLE_TYPE_PVP_ENSLAVE)
			{
				nCharIdOther  = msg[nIndex++];
				strCharNameOther  = msg[nIndex++];
				if(strCharNameOther != null && strCharNameOther.length > 0)
				{
					FrameInfo.showMessageDialog("","你战胜了 "+strCharNameOther+",是否抓作奴隶?",function handleOptionAddSlave(button:uint):void
					{
						if(button == JOptionPane.YES)
						{
							Client.getInstance().sendPacketLogic(1500,[_nTmpCharIdOther]);
						}
					},null,true,null,JOptionPane.YES|JOptionPane.NO);
					_nTmpCharIdOther = nCharIdOther;
				}
				//PanelMain.getInstance().leaveBattle();
			}

			PanelMain.getInstance().leaveBattle();
			
		}
		
		public static function phCompareInvite_308(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phCompareInvite_308", msg);
			var nIndex:uint = 0;
			var invite_char_id:int = msg[nIndex++];
			var invite_char_name:String = msg[nIndex++];
			
			var pane:FrameInfo = FrameInfo.showMessageDialog("","是否同意 "+invite_char_name+" 的切磋请求?",handleOptionTradeInvite,null,true,null,JOptionPane.YES|JOptionPane.NO);
			inviteCharId = invite_char_id;
			
		}
		public static var bWatchingBattle:Boolean = false;
		public static function phWatchBattle_310(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phWatchBattle_310", msg);
			var nIndex:uint = 0;
			bWatchingBattle = true;
			FrameBattle.hide();
			FrameBattleAuto.hide();
			FrameBattle.hidePartner();
			FrameBattleWatch.show();
		}
		public static function phWatchBattleExit_311(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phWatchBattleExit_311", msg);
			var nIndex:uint = 0;
			bWatchingBattle = false;
			
			FrameBattle.hide();
			FrameBattleAuto.hide();
			FrameBattle.hidePartner();
			PanelMain.getInstance().leaveBattle();
			FrameBattleWatch.hide();
		}
		private static var inviteCharId:uint = 0;
		private static function handleOptionTradeInvite(button:uint):void
		{
			Client.getInstance().sendPacketLogic(309,[inviteCharId,button == FrameInfo.YES?0:1]);
		}
		
		private var _nTmpCharIdOther:uint = 0;
		
		private static var objCharPrev:ObjectChar = null;
		public static function RoundPlay():void
		{
			//if(objCharPrev != null)
			//{
			//	objCharPrev.removeEffectSkillName();
			//	objCharPrev = null;
			//}
			if(roundPlayStep >= roundPlayBattler.length)
			{
				trace("roundPlayStep >= roundPlayBattler.length");
				Client.getInstance().sendPacketLogic(305,[SceneBattle.teamSelf,SceneBattle.indexSelf]);
				return;
			}
			var obj:Object = roundPlayBattler[roundPlayStep];
			if(m_arBattlers[obj.team][obj.index] == null)
				return;
			var objChar:ObjectChar = m_arBattlers[obj.team][obj.index].objChar;
			if(objChar == null)
				return;
			
			if(obj.skillid == 0 || obj.skillid == -1) //无
			{
				roundPlayStep++;
				RoundPlay();
				return;
			}
			
			var objSkillCSV:Object = null;
			objSkillCSV = Client.getInstance().GetSkillCSV(obj.skillid);
			objCharPrev = objChar;
			if(objSkillCSV.type != 1) //击打
			{
				//objChar.addEffectSkillName(objSkillCSV.name);
				addPanelSkillName(objChar,obj.skillid,objSkillCSV.name);
				addHPChange(objChar,obj.hp_change);
				objChar.setHP(obj.hp,obj.hp_max);
			}
			
			if(objSkillCSV.type == Const.SKILL_TYPE_JD) //击打
			{
				playSkillJD(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_FY) //防御
			{
				RoundPlayNext();
				return;
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_TP) //逃跑
			{
				playSkillTP(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_HF) //恢复
			{
				playSkillHF(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_TG) //忽悠
			{
				playSkillTG(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_HL) //忽悠
			{
				playSkillHL(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_BD) //震慑
			{
				playSkillBD(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_HS) //放电
			{
				playSkillHS(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_SL) //放电
			{
				playSkillSL(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_SD) //放电
			{
				playSkillSD(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_JZ) //勾魂
			{
				playSkillJZ(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_QS) //强身
			{
				playSkillQS(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_CF) //强身
			{
				playSkillRM(objChar,obj);
			}
			if(objSkillCSV.type == Const.SKILL_TYPE_JS) //强身
			{
				playSkillJS(objChar,obj);
			}
		}
		public static function playSkillTP(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}

			trace("playSkillTP,obj.skillTarget:",obj.skillTarget.length);
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				var oldDirection:int = objCharTarget.direction;// =  Directions.Left;
				if(objCharTarget.direction == Directions.Left)
					objCharTarget.direction = Directions.Right;
				else if(objCharTarget.direction == Directions.Right)
					objCharTarget.direction = Directions.Left;
				objCharTarget.setAction(Actions.Run,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,oldDirection:int):void
					{
						if(item.state[BATTLER_STATE_TP] == 1)
						{
							if(objCharTarget is ObjectCharPlayer)
							{
								if((objCharTarget as ObjectCharPlayer).userObject.m_nCharId == CharInfo.charId)
								{
									PanelMain.getInstance().leaveBattle();
									return;
								}
							}
							SceneBattle.getInstance().removeObject(objCharTarget)
						}
						else
						{
							objCharTarget.addEffectSkillName("逃跑失败");
						}
						objCharTarget.direction = oldDirection;
						objCharTarget.setHP(item.hp,item.hp_max);
						objCharTarget.setAction(Actions.Prepare);
						RoundPlayNext();
					},[objCharTarget,objSkillCSV,item,oldDirection]);
			}
		}
		public static function playSkillHF(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			var bTargetIncludeSelf:Boolean = false;
			var item:Object = null;
			for each(item in obj.skillTarget)
			{
				if(m_arBattlers[item.team][item.index].objChar == self)
				{
					bTargetIncludeSelf = true;
					break;
				}
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			{
				self.setAction(Actions.AttackMagic,
					function(self:ObjectChar,bTargetIncludeSelf:Boolean):void
					{
						if(!bTargetIncludeSelf)
							self.setAction(Actions.Prepare);
						RoundPlayNext();
					},[self,bTargetIncludeSelf]);
			}
			//self.addEffectSkillName("恢复");
			for each(item in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);

				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				item.play = false;
				objCharTarget.stop = false;
				objCharTarget.setAction(Actions.Prepare,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object):void
					{
						addHPChange(objCharTarget,item.hp_change);
						objCharTarget.setHP(item.hp,item.hp_max);
						if(item.state[BATTLER_STATE_DEAD] != 1 || item.hp > 0)
						{
							objCharTarget.stop = false;
							objCharTarget.setAction(Actions.Prepare);
							objCharTarget.alpha = 1;
						}
						if(item.state[BATTLER_STATE_DEAD] == 1 || item.hp <= 0)
						{
							objCharTarget.setAction(Actions.Die,
								function(objCharTarget:ObjectChar):void
								{
									objCharTarget.alpha = 0.5;
									objCharTarget.stop = true;
								},[objCharTarget],true);
						}
						item.play = true;
						for each(var skill:Object in obj.skillTarget)
						{
							if(skill.play == false)
								return;
						}
						//RoundPlayNext();
					},[objCharTarget,objSkillCSV,item]);
			}
		}
		public static function playSkillTG(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			var bTargetIncludeSelf:Boolean = false;
			var item:Object = null;
			for each(item in obj.skillTarget)
			{
				if(m_arBattlers[item.team][item.index].objChar == self)
				{
					bTargetIncludeSelf = true;
					break;
				}
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			{
				self.setAction(Actions.AttackMagic,
					function(self:ObjectChar,bTargetIncludeSelf:Boolean):void
					{
						if(!bTargetIncludeSelf)
							self.setAction(Actions.Prepare);
						RoundPlayNext();
					},[self,bTargetIncludeSelf]);
			}
			//self.addEffectSkillName("恢复");
			for each(item in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				item.play = false;
				objCharTarget.stop = false;
				objCharTarget.setAction(Actions.Prepare,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object):void
					{
						addHPChange(objCharTarget,item.hp_change);
						objCharTarget.setHP(item.hp,item.hp_max);
						if(item.state[BATTLER_STATE_DEAD] != 1 || item.hp > 0)
						{
							objCharTarget.stop = false;
							objCharTarget.setAction(Actions.Prepare);
							objCharTarget.alpha = 1;
						}
						if(item.state[BATTLER_STATE_DEAD] == 1 || item.hp <= 0)
						{
							objCharTarget.setAction(Actions.Die,
								function(objCharTarget:ObjectChar):void
								{
									objCharTarget.alpha = 0.5;
									objCharTarget.stop = true;
								},[objCharTarget],true);
						}
						item.play = true;
						for each(var skill:Object in obj.skillTarget)
						{
							if(skill.play == false)
								return;
						}
						//RoundPlayNext();
					},[objCharTarget,objSkillCSV,item]);
			}
		}
		
		public static function playSkillHL(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					self.setAction(Actions.Prepare);
				}
				,[self]);

			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object):void
					{
						objCharTarget.setAction(Actions.Prepare);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);
						updateEffect(objCharTarget,item.state);
						item.play = true;
						for each(var skill:Object in obj.skillTarget)
						{
							if(skill.play == false)
								return;
						}
						RoundPlayNext();
					},[objCharTarget,objSkillCSV,item]);
			}
		}
		public static function playSkillBD(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					src.setAction(Actions.Prepare);
				}
				,[self]);
			//self.addEffectSkillName("震慑");
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				SceneMain.shake(Client.getInstance(),3,3,20);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object):void
					{
						objCharTarget.setAction(Actions.Prepare);
						//if(item.state == 2) 
						//{
						//	objCharTarget.removeEffect(_effect_target_hit_FY);
						//	addEffect(objCharTarget,objSkillCSV.effect_target_hit);
						//}
						updateEffect(objCharTarget,item.state);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);
						item.play = true;
						for each(var skill:Object in obj.skillTarget)
						{
							if(skill.play == false)
								return;
						}
						RoundPlayNext();
					},[objCharTarget,objSkillCSV,item]);
			}
		}
		public static function playSkillHS(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					src.setAction(Actions.Prepare);
				}
				,[self]);
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				//SceneMain.shake(Client.getInstance(),3,3,20);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object):void
					{
						objCharTarget.setAction(Actions.Prepare);
						updateEffect(objCharTarget,item.state);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);
						item.play = true;
						for each(var skill:Object in obj.skillTarget)
						{
							if(skill.play == false)
								return;
						}
						RoundPlayNext();
					},[objCharTarget,objSkillCSV,item]);
			}
		}
		
		public static function playSkillSL(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					src.setAction(Actions.Prepare);
				}
				,[self]);
			//self.addEffectSkillName("放电");
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				//SceneMain.shake(Client.getInstance(),4,4,30);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
					{
						//objCharTarget.addEffectHPChange(item.hp_change,1.5);
						addHPChange(objCharTarget,item.hp_change);
						objCharTarget.setHP(item.hp,item.hp_max);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);
						//SceneMain.shake(Client.getInstance());
						updateEffect(objCharTarget,item.state);
						if(item.state[BATTLER_STATE_DEAD] == 1 || item.hp <= 0)
						{
							objCharTarget.setAction(Actions.Die,
								function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
								{
									objCharTarget.alpha = 0.5;
									objCharTarget.stop = true;
									item.play = true;
									//updateEffect(objCharTarget,item.state);
									for each(var skill:Object in obj.skillTarget)
									{
										if(skill.play == false)
											return;
									}
									RoundPlayNext();
								},[objCharTarget,objSkillCSV,item,obj],true);
						}
						else
						{
							objCharTarget.setAction(Actions.Prepare);
							item.play = true;
							for each(var skill:Object in obj.skillTarget)
							{
								if(skill.play == false)
									return;
							}
							RoundPlayNext();
						}
					},[objCharTarget,objSkillCSV,item,obj]);
			}
		}
		
		public static function playSkillSD(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					src.setAction(Actions.Prepare);
				}
				,[self]);
			//self.addEffectSkillName("放电");
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				SceneMain.shake(Client.getInstance(),4,4,30);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
					{
						//objCharTarget.addEffectHPChange(item.hp_change,1.5);
						addHPChange(objCharTarget,item.hp_change);
						objCharTarget.setHP(item.hp,item.hp_max);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);
						//SceneMain.shake(Client.getInstance());
						if(item.state[BATTLER_STATE_DEAD] == 1 || item.hp <= 0)
						{
							objCharTarget.setAction(Actions.Die,
								function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
								{
									objCharTarget.alpha = 0.5;
									objCharTarget.stop = true;
									item.play = true;
									//objCharTarget.removeEffect(_effect_target_hit_FY);
									//objCharTarget.removeEffect(_effect_target_hit_ZS);
									updateEffect(objCharTarget,item.state);
									for each(var skill:Object in obj.skillTarget)
									{
										if(skill.play == false)
											return;
									}
									RoundPlayNext();
								},[objCharTarget,objSkillCSV,item,obj],true);
						}
						else
						{
							objCharTarget.setAction(Actions.Prepare);
							item.play = true;
							for each(var skill:Object in obj.skillTarget)
							{
								if(skill.play == false)
									return;
							}
							RoundPlayNext();
						}
					},[objCharTarget,objSkillCSV,item,obj]);
			}
		}
		public static function playSkillJZ(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					src.setAction(Actions.Prepare);
				}
				,[self]);
			//self.addEffectSkillName("勾魂");
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
					{
						//objCharTarget.addEffectHPChange(item.hp_change,1.5);
						addHPChange(objCharTarget,item.hp_change);
						objCharTarget.setHP(item.hp,item.hp_max);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);
						if(item.state[BATTLER_STATE_DEAD] == 1 || item.hp <= 0)
						{
							objCharTarget.setAction(Actions.Die,
								function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
								{
									objCharTarget.alpha = 0.5;
									objCharTarget.stop = true;
									item.play = true;
									updateEffect(objCharTarget,item.state);
									for each(var skill:Object in obj.skillTarget)
									{
										if(skill.play == false)
											return;
									}
									RoundPlayNext();
								},[objCharTarget,objSkillCSV,item,obj],true);
						}
						else
						{
							objCharTarget.setAction(Actions.Prepare);
							item.play = true;
							for each(var skill:Object in obj.skillTarget)
							{
								if(skill.play == false)
									return;
							}
							RoundPlayNext();
						}
						//updateEffect(objCharTarget,item.state);
						//RoundPlayNext();
					},[objCharTarget,objSkillCSV,item,obj]);
			}
		}
		public static function playSkillQS(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					src.setAction(Actions.Prepare);
				}
				,[self]);
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
					{
						//objCharTarget.addEffectHPChange(item.hp_change,1.5);
						objCharTarget.setHP(item.hp,item.hp_max);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);

						updateEffect(objCharTarget,item.state);
						
						objCharTarget.setAction(Actions.Prepare);
						item.play = true;
						for each(var skill:Object in obj.skillTarget)
						{
							if(skill.play == false)
								return;
						}
						RoundPlayNext();

					},[objCharTarget,objSkillCSV,item,obj]);
			}
		}
		public static function playSkillRM(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					src.setAction(Actions.Prepare);
				}
				,[self]);
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
					{
						//objCharTarget.addEffectHPChange(item.hp_change,1.5);
						objCharTarget.setHP(item.hp,item.hp_max);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);
						
						updateEffect(objCharTarget,item.state);
						
						objCharTarget.setAction(Actions.Prepare);
						item.play = true;
						for each(var skill:Object in obj.skillTarget)
						{
							if(skill.play == false)
								return;
						}
						RoundPlayNext();
						
					},[objCharTarget,objSkillCSV,item,obj]);
			}
		}
		public static function playSkillJS(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				self.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[self],true);
			}
			else
			self.setAction(Actions.AttackMagic,
				function(src:ObjectChar):void
				{
					src.setAction(Actions.Prepare);
				}
				,[self]);
			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var objSkillCSV:Object = Client.getInstance().GetSkillCSV(obj.skillid);
				addEffect(objCharTarget,objSkillCSV.effect_target_attacked);
				item.play = false;
				objCharTarget.setAction(Actions.Attacked,
					function(objCharTarget:ObjectChar,objSkillCSV:Object,item:Object,obj:Object):void
					{
						//objCharTarget.addEffectHPChange(item.hp_change,1.5);
						objCharTarget.setHP(item.hp,item.hp_max);
						//removeEffect(objCharTarget,objSkillCSV.effect_target_attacked);
						
						updateEffect(objCharTarget,item.state);
						
						objCharTarget.setAction(Actions.Prepare);
						item.play = true;
						for each(var skill:Object in obj.skillTarget)
						{
							if(skill.play == false)
								return;
						}
						RoundPlayNext();
						
					},[objCharTarget,objSkillCSV,item,obj]);
			}
		}
		public static function playSkillJD(self:ObjectChar, obj:Object):void 
		{
			if(obj.skillTarget.length == 0)
			{
				RoundPlayNext();
				return;
			}

			for each(var item:Object in obj.skillTarget)
			{
				var objCharTarget:ObjectChar = m_arBattlers[item.team][item.index].objChar;
				var oldDirection:int = self.direction;// =  Directions.Left;
				item.oldDirection = objCharTarget.direction;

				var destX:int = objCharTarget.x;

				var distance:int = 60;
				if(destX > self.x)
				{
					destX -= distance;//objCharTarget.width/2;
					self.direction = Directions.Right;
					objCharTarget.direction = Directions.Left;
				}
				if(destX < self.x)
				{
					destX += distance;//objCharTarget.width/2;
					self.direction = Directions.Left;
					objCharTarget.direction = Directions.Right;
				}
				if(destX == self.x)
				{
					if(item.team == 1)
					{
						if(SceneBattle.teamSelf == 0)
						{
							destX -= distance;//objCharTarget.width/2;
							self.direction = Directions.Right;
							objCharTarget.direction = Directions.Left;
						}
						else
						{
							destX += distance;//objCharTarget.width/2;
							self.direction = Directions.Left;
							objCharTarget.direction = Directions.Right;
						}
					}
					if(item.team == 0)
					{
						if(SceneBattle.teamSelf == 0)
						{
							destX += distance;//objCharTarget.width/2;
							self.direction = Directions.Left;
							objCharTarget.direction = Directions.Right;
						}
						else
						{
							destX -= distance;//objCharTarget.width/2;
							self.direction = Directions.Right;
							objCharTarget.direction = Directions.Left;
						}
					}
					//destX += objCharTarget.width/2;
					//self.direction = Directions.Left;
					//objCharTarget.direction = Directions.Right;
				}
				self.zOrderOffset = objCharTarget.y-self.y+10;
				
				self.setAction(Actions.Prepare);
				
				self.realTimeUpdatePos = false;
				objCharTarget.realTimeUpdatePos = false;
				
				var tween:TweenLite = TweenLite.to(self, (item.team != obj.team) ? 0.3 : 0.15, {x:destX, y:objCharTarget.y,onComplete:onJDFinishTweenGo,onCompleteParams:[self,objCharTarget,item,oldDirection,obj]});
				//tweenArray.push(tween);
			}
		}
		public static function playSkillLJ1(src:ObjectChar,dest:ObjectChar,item:Object,oldDirection:int,obj:Object):void 
		{
			src.setAction(Actions.Attack,
				function(src:ObjectChar,dest:ObjectChar,item:Object,oldDirection:int,obj:Object):void
				{
					//dest.addEffectHPChange(item.m_nLJHPChange1,1.5);
					addHPChange(dest,item.m_nLJHPChange1);
					//dest.setHP(item.hp,item.hp_max);
					dest.setHP(dest._hp+item.m_nLJHPChange1,dest._hp_max);
					//if(item.m_bBJ == 1)
					//{
					//	dest.addEffectSkillName("暴击");
					//}
					if(item.m_bLJ == 1)
					{
						src.setAction(Actions.Prepare);
						dest.setAction(Actions.Prepare);
						playSkillLJ2(src,dest,item,oldDirection,obj);
						//LJPlayNext();
					}
					//else
					//{
					//	src.setAction(Actions.FlyingBack,null,null,true);
					//	var tween:TweenLite = TweenLite.to(src,0.3,{x:src.getPos().x, y:src.getPos().y,onComplete:onJDFinishTweenBack,onCompleteParams:[src,dest,item,oldDirection]});
					//}
				}
				,[src,dest,item,oldDirection,obj]);
			
			dest.setAction(Actions.Attacked,
				function(src:ObjectChar,dest:ObjectChar,item:Object):void 
				{
					if(item.m_bLJ == 1)
					{
						
					}
					updateEffect(dest,item.state);
					//dest.direction = item.oldDirection;
				},[src,dest,item]);
			
			src.stop = false;
			dest.stop = false;
		}
		public static function playSkillLJ2(src:ObjectChar,dest:ObjectChar,item:Object,oldDirection:int,obj:Object):void 
		{
			src.setAction(Actions.Attack,
				function(src:ObjectChar,dest:ObjectChar,item:Object,oldDirection:int,obj:Object):void
				{
					addHPChange(dest,item.m_nLJHPChange2);
					dest.setHP(dest._hp+item.m_nLJHPChange2,dest._hp_max);

					src.setAction(Actions.Prepare);
					var tween:TweenLite = TweenLite.to(src,0.15,{x:src.getPos().x, y:src.getPos().y,onComplete:onJDFinishTweenBack,onCompleteParams:[src,dest,item,oldDirection,obj]});
					
				}
				,[src,dest,item,oldDirection,obj]);
			
			dest.setAction(Actions.Attacked,
				function(src:ObjectChar,dest:ObjectChar,item:Object,obj:Object):void 
				{
						if(item.state[BATTLER_STATE_DEAD] == 1 || item.hp <= 0)
						{
							dest.setAction(Actions.Die,
								function(objCharTarget:ObjectChar):void
								{
									objCharTarget.alpha = 0.5;
									RoundPlayNext();
								},[dest],true);
						}
						else
						{
							dest.setAction(Actions.Prepare);
							RoundPlayNext();
							
						}
						updateEffect(dest,item.state);
						dest.direction = item.oldDirection;
				},[src,dest,item,obj]);
			
			src.stop = false;
			dest.stop = false;
		}
		
		public static function onJDFinishTweenGo(src:ObjectChar,dest:ObjectChar,item:Object,oldDirection:int,obj:Object):void 
		{
			if(item.m_bBJ == 1)
			{
				//dest.addEffectSkillName("暴击");
				addEffect(dest,EFFECT_ID_BJ,true);
			}
			if(item.m_bSB == 1)
			{
				//dest.addEffectSkillName("闪避");
				addEffect(dest,EFFECT_ID_SB,true);
			}
			src.setAction(Actions.Attack,
				function(src:ObjectChar,dest:ObjectChar,item:Object,oldDirection:int,obj:Object):void
				{
					//dest.addEffectHPChange(item.hp_change,1.5);
					addHPChange(dest,item.hp_change);
					dest.setHP(dest._hp+item.hp_change,dest._hp_max);
					//if(item.m_bBJ == 1)
					//{
						//dest.addEffectSkillName("暴击");
					//	addEffect(dest,EFFECT_ID_BJ,true);
					//}
					//if(item.m_bSB == 1)
					//{
						//dest.addEffectSkillName("闪避");
					//	addEffect(dest,EFFECT_ID_SB,true);
					//}
					if(item.m_bLJ == 1)
					{
						//src.addEffectSkillName("连击");
						addEffect(dest,EFFECT_ID_LJ,true);
						src.setAction(Actions.Prepare);
						dest.setAction(Actions.Prepare);
						playSkillLJ1(src,dest,item,oldDirection,obj);
						return;
					}
					
					if(item.m_bFJ == 1)
					{
						src.setAction(Actions.Prepare);
						dest.setAction(Actions.Prepare);
						//src.stop = false;
						//dest.stop = false;
						if(item.state[BATTLER_STATE_DEAD] == 1 || item.hp <= 0)
						{
							dest.setAction(Actions.Die,
								function(objCharTarget:ObjectChar):void
								{
									objCharTarget.alpha = 0.5;
									RoundPlayNext();
								},[dest],true);
							updateEffect(dest,item.state);
							//src.setAction(Actions.Prepare,null,null,true);
							TweenLite.to(src,0.15,{x:src.getPos().x, y:src.getPos().y,onComplete:onJDFinishTweenBack,onCompleteParams:[src,dest,item,oldDirection,obj]});
						}
						else
						{
							//dest.addEffectSkillName("反击");
							addEffect(dest,EFFECT_ID_FJ,true);
							dest.setAction(Actions.Attack,
								function(src:ObjectChar,dest:ObjectChar,item:Object,oldDirection:int,obj:Object):void
								{
									src.setHP(obj.hp,obj.hp_max);
									addHPChange(src,item.m_nFJHPChange);
	
									dest.setAction(Actions.Prepare);
									src.setAction(Actions.Prepare);
									TweenLite.to(src,0.15,{x:src.getPos().x, y:src.getPos().y,onComplete:onJDFinishTweenBack,onCompleteParams:[src,dest,item,oldDirection,obj]});
								}
								,[src,dest,item,oldDirection,obj]);
							
							src.setAction(Actions.Attacked,
								function(src:ObjectChar,dest:ObjectChar,item:Object):void 
								{
									updateEffect(dest,item.state);
									RoundPlayNext();
									dest.direction = item.oldDirection;
									
									
								},[src,dest,item]);
						}
						
						src.stop = false;
						dest.stop = false;
						return;
					}
					//else
					//{
						//src.setAction(Actions.Prepare,null,null,true);
						TweenLite.to(src,0.15,{x:src.getPos().x, y:src.getPos().y,onComplete:onJDFinishTweenBack,onCompleteParams:[src,dest,item,oldDirection,obj]});
					//}
				}
				,[src,dest,item,oldDirection,obj]);
			
			dest.setAction(Actions.Attacked,
				function(src:ObjectChar,dest:ObjectChar,item:Object):void 
				{
					if(item.m_bLJ != 1 && item.m_bFJ != 1)
					{
						updateEffect(dest,item.state);
						if(item.state[BATTLER_STATE_DEAD] == 1 || item.hp <= 0)
						{
							dest.setAction(Actions.Die,
								function(objCharTarget:ObjectChar):void
								{
									objCharTarget.alpha = 0.5;
									RoundPlayNext();
								},[dest],true);
						}
						else
						{
							dest.setAction(Actions.Prepare);
							RoundPlayNext();
						}
						updateEffect(dest,item.state);
						dest.direction = item.oldDirection;
					}
					
				},[src,dest,item]);
			
			src.stop = false;
			dest.stop = false;
			
		}
	
		public static function onJDFinishTweenBack(src:ObjectChar,dest:ObjectChar,item:Object,oldDirection:int,obj:Object):void 
		{
			src.setAction(Actions.Prepare);
			src.zOrderOffset = 0;
			src.stop = false;
			src.direction = oldDirection;
			
			if(obj.state[BATTLER_STATE_DEAD] == 1 || obj.hp <= 0)
			{
				src.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
					},[src],true);
			}
				
			//RoundPlayNext();
		}
		
		private static var _timer:Timer = null;
		public static function RoundPlayNext():void
		{
			roundPlayStep++;
			if(_timer == null)
			{
				_timer = new Timer(1000);
				_timer.addEventListener(TimerEvent.TIMER,onTimerRoundPlayNext);
			}
			if(!_timer.running)
			_timer.start();
		}
		
		public static function onTimerRoundPlayNext(e:TimerEvent):void
		{
			_timer.stop();
			RoundPlay();
			
		}
		
		public static function addPanelSkillName(dest:ObjectChar,csv_id:int,name:String,time:int = 2.5):void
		{
			//FrameBattleCountDown.show();
			var panel:PanelSkillName = new PanelSkillName;
			if(!panel.setSkillName(csv_id))
				dest.addEffectSkillName(name);
			else
				dest.addPanelSkillName(panel,time);
		}
		
		public static function addHPChange(dest:ObjectChar,hp:int,time:int = 1.5):void
		{
			//FrameBattleCountDown.show();
			var hpChange:PanelHPChange = new PanelHPChange;
			hpChange.setHP(hp);
			dest.addHPChange(hpChange);
		}
		public static function addEffect(dest:ObjectChar,effect_id:int,bTop:Boolean = false,bRemoveAtEnd:Boolean = true,bBackward:Boolean = false):void
		{
			if(dest == null)
				return;
			var mc_effect:MovieClip = Client.getEffectElement("mc_effect_" + effect_id) as MovieClip;
			if(mc_effect == null)
				return;
			dest.addEffect(effect_id,mc_effect,bTop,bRemoveAtEnd,bBackward);
		}
		public static function removeEffect(dest:ObjectChar,effect_id:int):void
		{
			dest.removeEffect(effect_id);
		}
		public static function updateEffect(objChar:ObjectChar,state:Array):void
		{
			for(var j:int = 0; j < BATTLER_STATE_SIZE; j++)
			{
				if(_effect_target_hit[j] == null)
					continue;
				if(state[j] == 0)
				{
					//if(j == BATTLER_STATE_HL)
					//{
					//	trace("_effect_target_hit[j]:"+_effect_target_hit[j]);
					//}
					if(objChar.hasEffect(_effect_target_hit[j]))
					{
						objChar.removeEffect(_effect_target_hit[j]);
					}
				}
				else
				{
					//if(j == BATTLER_STATE_HL)
					//{
					//	trace("_effect_target_hit[j]:"+_effect_target_hit[j]);
					//}
					if(!objChar.hasEffect(_effect_target_hit[j]))
					{
						addEffect(objChar,_effect_target_hit[j],j == BATTLER_STATE_CM || j == BATTLER_STATE_RM || j == BATTLER_STATE_HL,false);
					}
				}
			}
			/*if(state[BATTLER_STATE_DEAD] == 1)
			{
				objChar.setAction(Actions.Die,
					function(objCharTarget:ObjectChar):void
					{
						objCharTarget.alpha = 0.5;
						//RoundPlayNext();
					},[objChar],true);
				//updateEffect(dest,item.state);
			}
			else
			{
				objChar.setAction(Actions.Prepare);
			}*/
		}
		public  function loadBattle(scene:SceneMain,effect:Boolean = true):void
		{
			clearup();
			startup();
			updateBackground(scene);
			if(effect)
				enterBattleEffect();
		}
		public function updateBackground(scene:SceneMain):void
		{
			scene.map.needUpdate = true;
			scene.map.render(_mainBitmapData,true);
			/*scene.map.render(_battleBackground,true);
			var bm:Bitmap = new Bitmap(_battleBackground);
			bm.filters = new Array(new BlurFilter(3,3,3));
			_mainBitmapData.draw(bm);
			bm = null;*/
		}
		//private var enteringBattle:Boolean = false;
		public function enterBattleEffect():void
		{
			//if(enteringBattle)
			//	return;
			//TransitionManager.start(this, {type:Blinds, direction:Transition.IN, duration:2, easing:None.easeNone, startPoint:1});
			
			this.alpha = 0.1;
			if(_tween != null)
			{
				_tween.clear();
				_tween = null;
			}
			_tween = TweenLite.to(this, 2.0, {autoAlpha:1.0});
			
			/*FrameFullScreenEffect.show();
			var mc_effect:MovieClip = Client.getEffectElement("mc_effect_" + 4000000) as MovieClip;
			if(mc_effect == null)
				return;
			//dest.addEffect(effect_id,mc_effect,bTop,bRemoveAtEnd,bBackward);
			FrameFullScreenEffect._frame.addEffect(4000000,mc_effect,true,onEnterBattleEffectEnd);
			enteringBattle = true;*/
		}
		public function onEnterBattleEffectEnd():void
		{
			//enteringBattle = false;
			//PanelMain.getInstance().enterBattle();
		}
		static private var _tween:TweenLite = null;
		public function getPosition(team:uint,rowCount:uint,index:uint):Point
		{
			/*if(rowCount == 1)
			{
				if(team == 0)
				{
					switch(index)
					{
						case 0:
							return new Point(130,420);
						case 1:
							return new Point(230,420);
						case 2:
							return new Point(130,420);
						case 3:
							return new Point(230,420);
						case 4:
							return new Point(130,420);
						case 5:
							return new Point(230,420);
					}
				}
				if(team == 1)
				{
					switch(index)
					{
						case 0:
							return new Point(670,420);
						case 1:
							return new Point(570,420);
						case 2:
							return new Point(670,420);
						case 3:
							return new Point(570,420);
						case 4:
							return new Point(670,420);
						case 5:
							return new Point(570,420);
					}
					
				}
			}
			if(rowCount == 2)
			{
				if(team == 0)
				{
					switch(index)
					{
						case 0:
							return new Point(130,470);
						case 1:
							return new Point(230,470);
						case 2:
							return new Point(130,370);
						case 3:
							return new Point(230,370);
						case 4:
							return new Point(130,370);
						case 5:
							return new Point(230,370);
					}
				}
				if(team == 1)
				{
					switch(index)
					{
						case 0:
							return new Point(670,470);
						case 1:
							return new Point(570,470);
						case 2:
							return new Point(670,370);
						case 3:
							return new Point(570,370);
						case 4:
							return new Point(670,370);
						case 5:
							return new Point(570,370);
					}
					
				}
			}
			if(rowCount == 3)
			{*/
				if(team == 0)
				{
					switch(index)
					{
						case 0:
							return new Point(280,420);
						case 1:
							return new Point(430,420);
						case 2:
							return new Point(230,340);
						case 3:
							return new Point(380,340);
						case 4:
							return new Point(230,500);
						case 5:
							return new Point(380,500);
					}
				}
				if(team == 1)
				{
					switch(index)
					{
						case 0:
							return new Point(920,420);
						case 1:
							return new Point(770,420);
						case 2:
							return new Point(970,340);
						case 3:
							return new Point(820,340);
						case 4:
							return new Point(970,500);
						case 5:
							return new Point(820,500);
					}
					
				}
			//}
			return new Point(0,0);
		}
		override public function clearup():void
		{
			if(_tween != null)
			{
				_tween.clear();
				_tween = null;
			}
			if(_timer != null)
			{
				_timer.stop();
				//_timer.removeEventListener(TimerEvent.TIMER,onTimerRoundPlayNext);
				//_timer = null;
			}
			//m_arBattlers.splice(0,m_arBattlers.length);
			if(m_arBattlers[0].length > 0)
				m_arBattlers[0].splice(0,m_arBattlers[0].length);
			if(m_arBattlers[1].length > 0)
				m_arBattlers[1].splice(0,m_arBattlers[1].length);
			objCharPrev = null;
			_oldSkillTarget = null;
			if(roundPlayBattler.length > 0)
				roundPlayBattler.splice(0,roundPlayBattler.length);
			super.clearup();
		}
		private var _oldSkillTarget:ObjectChar = null;
		override public function onClickObject(obj:ObjectBase):void
		{
			if(!(obj is ObjectChar))
				return;
			var tmp:Sprite = obj as Sprite;
			if(tmp != null)
			{
				if(_oldSkillTarget != null)// && (_oldSkillTarget as Sprite).filters != null)
				{
					//_oldSkillTarget.textName.textColor = 0xffffff;
					removeEffect(_oldSkillTarget as ObjectChar,1000000);
					if(obj == _oldSkillTarget)
					{
						FrameBattle.setSkillTarget(-1,-1);
						Client.getInstance().sendPacketLogic(307,[SceneBattle.teamSelf,SceneBattle.indexSelf,-1,-1]);
						_oldSkillTarget = null;
						return;
					}
					_oldSkillTarget = null;
				}
				var objBattler:Object = obj.userObject;
				FrameBattle.setSkillTarget(objBattler.team,objBattler.index);
				Client.getInstance().sendPacketLogic(307,[SceneBattle.teamSelf,SceneBattle.indexSelf,int(objBattler.team),int(objBattler.index)]);
				//obj.textName.textColor = 0xffff00;
				_oldSkillTarget = obj as ObjectChar;
				addEffect(_oldSkillTarget,1000000,false,false,true);
			}
			
		}
		
	}
}